package uc.codecraft.webmagic.web.model;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.TargetUrl;
import us.codecraft.webmagic.pipeline.PageModelPipeline;

import java.util.List;

/**
 * @author code4crafter@gmail.com <br>
 */
@TargetUrl("https://www.oschina.net/blog*")
@Data
public class OschinaBlog {

    private static final Logger LOGGER = LoggerFactory.getLogger(OschinaBlog.class);

    @ExtractBy("//title")
    private String title;

//    @ExtractBy(value = "//div.BlogContent", type = ExtractBy.Type.Css)
//    private String content;

    @ExtractBy(value = "//div[@class='header']/a/text()", multi = true)
    private List<String> tags;

    public String getTitle() {
        return title;
    }

   /* public String getContent() {
        return content;
    }*/

    public List<String> getTags() {
        return tags;
    }

    public static class OschinaBlogPageModelPipeline implements PageModelPipeline<OschinaBlog> {

        @Override
        public void process(OschinaBlog oschinaBlog, Task task) {
            LOGGER.info("{}", oschinaBlog);
        }
    }

}
